home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / opal / devdocs.lha / OpalReq / FileReqDemo.c < prev   
C/C++ Source or Header  |  1993-05-04  |  4KB  |  170 lines

  1. /* 
  2.  * FileReqDemo.c 
  3.  *
  4.  * 17/12/91 By Martin Boyd.
  5.  *
  6.  * Simple File requester example. Uses the OpalRequester to input
  7.  * filenames and displays the selected files. Selecting cancel exits.
  8.  */
  9.  
  10.  
  11. #include "graphics/gfxbase.h"
  12. #include <opal/opallib.h>
  13. #include <opal/OpalReqlib.h>
  14. #include <exec/memory.h>
  15. #include <proto/all.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #define BLACK        0L
  21. #define GREY        1L
  22. #define BLUE        2L
  23. #define WHITE        3L
  24.  
  25.  
  26. struct NewScreen NewScreen =
  27.     { 0,0,640,512,2,
  28.       BLUE,GREY,LACE|HIRES,
  29.       CUSTOMSCREEN|SCREENQUIET,
  30.       NULL,NULL,NULL,NULL
  31.     };
  32.  
  33.  
  34. struct NewWindow NewWind =
  35.     { 0,0,640,512,BLUE,GREY,
  36.       NULL,BORDERLESS|ACTIVATE,
  37.       NULL,NULL,NULL,NULL,NULL,
  38.       0,0,1,0,CUSTOMSCREEN
  39.     };
  40.  
  41.  
  42. USHORT Palette[] =
  43.     { 0x0001,            /* Colour 0 */
  44.       0x0666,            /* Colour 1 */
  45.       0x0346,            /* Colour 2 */
  46.       0x0999,            /* Colour 3 */
  47.       0x0000,0x0000,0x0000,0x0000,    /* Colours 4..7   */
  48.       0x0000,0x0000,0x0000,0x0000,    /* Colours 8..11  */
  49.       0x0000,0x0000,0x0000,0x0000,    /* Colours 12..15 */
  50.       0x0001,0x0666,0x0001,0x0ABD    /* Colours 16..19 */
  51.     };
  52.  
  53.  
  54. __chip USHORT MousePointer[] =
  55.     { 0x0000,0x0000,
  56.       0x0000,0xFC00, 0x7C00,0xFE00, 0x7C00,0x8600, 0x7800,0x8C00,
  57.       0x7C00,0x8600, 0x6E00,0x9300, 0x0700,0x6980, 0x0380,0x04C0,
  58.       0x01C0,0x0260, 0x0080,0x0140, 0x0000,0x0080, 0x0000,0x0000,
  59.       0x0000,0x0000,
  60.     };
  61.  
  62.  
  63. struct IntuitionBase *IntuitionBase;
  64. struct GfxBase *GfxBase;
  65. struct OpalBase *OpalBase;
  66. struct OpalReqBase *OpalReqBase;
  67. struct OpalReq OReq;
  68. struct Screen *Scrn;
  69. struct Window *Wind;
  70. struct OpalScreen *OScrn;
  71. BYTE Dir[200],FullName[231];
  72. BYTE FileName[31];
  73. char *ChipSave;
  74.  
  75. #define AND &&
  76. #define OR ||
  77.  
  78. void CleanUp (char *String);
  79.  
  80. void main(void)
  81. {
  82.    register int i;
  83.    long Err;
  84.  
  85.  
  86.     GfxBase = (struct GfxBase *)
  87.         OpenLibrary ("graphics.library",0L);
  88.     IntuitionBase = (struct IntuitionBase *)
  89.         OpenLibrary ("intuition.library",0L);
  90.     OpalReqBase = (struct OpalReqBase *)
  91.         OpenLibrary ("opalreq.library",0L);
  92.     OpalBase = (struct OpalBase *)
  93.         OpenLibrary ("opal.library",0L);
  94.  
  95.     if ((OpalBase==NULL) OR (OpalReqBase==NULL) OR
  96.          (IntuitionBase==NULL) OR (GfxBase==NULL))
  97.             CleanUp ("Error openning libraries\n");
  98.  
  99.     NewScreen.Height = GfxBase->NormalDisplayRows*2;
  100.     NewWind.Height = NewScreen.Height;
  101.  
  102.     if ((Scrn = OpenScreen (&NewScreen))==NULL)
  103.         CleanUp ("Can't open intuition screen.\n");
  104.     LoadRGB4 (&Scrn->ViewPort,Palette,20L);
  105.     NewWind.Screen = Scrn;
  106.     if ((Wind = OpenWindow (&NewWind))==NULL)
  107.         CleanUp ("Can't open window.\n");
  108.  
  109.     OScrn = OpenScreen24 (0);
  110.     OReq.Hail = "Pick an Image";
  111.     OReq.OScrn = OScrn;
  112.     OReq.File = FileName;
  113.     OReq.Dir = Dir;
  114.     OReq.Window = Wind;
  115.     OReq.Pointer = MousePointer;
  116.     OReq.PrimaryPen = WHITE;
  117.     OReq.SecondaryPen = BLUE;
  118.     OReq.BackPen = GREY;
  119.     WaitTOF();
  120.     SetPointer (Wind,MousePointer,11L,16L,-1L,-1L);
  121.     SetSprite24 (MousePointer,0L);
  122.  
  123.     do
  124.         { AmigaPriority ();
  125.           DualDisplay24 ();
  126.           OpalRequester (&OReq);
  127.           strcpy (FullName,Dir);
  128.           i = strlen (FullName);
  129.           if ((i!=0) AND (FullName[i-1]!=':'))
  130.             strcat (FullName,"/");
  131.           strcat (FullName,FileName);
  132.           if (OReq.OKHit)
  133.             { CloseScreen24 ();
  134.               OScrn = NULL;
  135.               ChipSave = AllocMem (80*1024L,MEMF_CHIP);
  136.               if (ChipSave==NULL)
  137.                 CleanUp ("Out of memory !!\n");
  138.               Err = LoadImage24 (OScrn,FullName,0);
  139.               if (Err<OL_ERR_MAXERR)
  140.                 { FreeMem (ChipSave,80*1024L);
  141.                   CleanUp ("Error loading file\n");
  142.                 }
  143.               OScrn = (struct OpalScreen *)Err;
  144.               FreeMem (ChipSave,80*1024L);
  145.               SetSprite24 (NULL,0L);
  146.               Refresh24 ();
  147.               SetSprite24 (MousePointer,0L);
  148.             }
  149.         }
  150.     while (OReq.OKHit);
  151.  
  152.     CleanUp (NULL);
  153. }
  154.  
  155.  
  156. void CleanUp (char *String)
  157. {
  158.     if (Wind!=NULL) CloseWindow (Wind);
  159.     if (Scrn!=NULL) CloseScreen (Scrn);
  160.     if (OScrn!=NULL) CloseScreen24 ();
  161.     if (IntuitionBase!=NULL) CloseLibrary ((struct Library *)IntuitionBase);
  162.     if (GfxBase!=NULL) CloseLibrary ((struct Library *)GfxBase);
  163.     if (OpalReqBase!=NULL) CloseLibrary ((struct Library *)OpalReqBase);
  164.     if (OpalBase!=NULL) CloseLibrary ((struct Library *)OpalBase);
  165.     if (String!=NULL)
  166.         puts (String);
  167.     exit (0);
  168. }
  169.  
  170.